package summary;

/**
 * @Author: 海琳琦
 * @Date: 2022/3/11 17:55
 * https://leetcode-cn.com/problems/combination-sum-iv/
 */
public class Title377 {

    /**
     * dp[i]表示装满容量为i的背包的方案数
     * 递推公式：dp[j] += dp[j-nums[i]]
     * 初始化：dp[0] = 1
     * @param nums
     * @param target
     * @return
     */
    public int combinationSum4(int[] nums, int target) {
        int[] dp = new int[target + 1];
        dp[0] = 1;
        for (int j = nums[0]; j <= target ; j++) {
            for (int i = 0; i < nums.length; i++) {
                if (j - nums[i] >= 0) {
                    dp[j] += dp[j - nums[i]];
                }
            }
        }
        return dp[target];
    }

    public static void main(String[] args) {

    }
}
